#!coding=utf-8
from django.shortcuts import *
from map_data.models import *

def map(request):
	_enterPrise = request.session.get('ep',None)

	if not _enterPrise:
		return HttpResponse('当前用户信息错误')

	_mdcList = MapDataCategory.objects.all()
	_mdcNames = []

	_points,_centerPoint,_extent = _enterPrise.getGeoData()

	if not _points and not _centerPoint and not _extent:
		_points,_centerPoint,_extent = '[]','[]','[]'

	_pPoints,_pCenterPoint = _enterPrise.getParkGeoData()

	if not _pPoints and not _pCenterPoint:
		_pPoints,_pCenterPoint = '[]','[]'

	for _mdc in _mdcList:
		_tmp = {}
		_tmp['name'] = _mdc.name
		_tmp['key'] = _mdc.key
		_mdcNames.append( _tmp )

	_mapData = [
		{'name':'production','url':'/facilities/productAreaGeo/'},
		{'name':'storage','url':'/facilities/storageAreaGeo/'}
	]

	print _enterPrise.park.geo_extent

	_tmpData = { 
		'mdcNames' : _mdcNames, 
		'mapData': _mapData,
		'e':{
			'centerPoint': _centerPoint,
			'points': _points
		},
		'p':{
			'centerPoint': _pCenterPoint,
			'points': _pPoints,
			'extent': _enterPrise.park.geo_extent
		},
		'enterprise':_enterPrise
	}

	return render_to_response('enterprise/map/map.html', _tmpData ,context_instance = RequestContext(request))


def smap(request):
	return render_to_response('enterprise/map/showMap.html')